package com.xxx.service.impl;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xxx.common.IdWorkerManage;
import com.xxx.common.dto.Page;
import com.xxx.common.dto.Pagination;
import com.xxx.dao.IllnessDao;
import com.xxx.model.Illness;
import com.xxx.service.IllnessService;

@Service
public class IllnessServiceImpl implements IllnessService {
	
	@Autowired
	private IllnessDao illnessDao;
	
	@Override
	@Transactional(rollbackFor=Exception.class)
	public long saveOrUpdate(Illness illness) throws Exception {
		if(illness.getId() == null){
			illness.setId(IdWorkerManage.getId());
			return illnessDao.save(illness);
		}
		return illnessDao.update(illness);
	}

	@Override
	@Transactional(rollbackFor=Exception.class)
	public boolean delete(long id) throws Exception{
		return illnessDao.delete(id);
	}

	@Override
	public Illness getEntity(long id) throws Exception{
		return illnessDao.getEntity(id);
	}

	@Override
	public int getCount(Map<String, Object> whereMap) {
		return illnessDao.getCount(whereMap);
	}
	
	@Override
	public List<Illness> getList(Map<String, Object> whereMap) {
		return illnessDao.getList(whereMap);
	}

	@Override
	public List<Illness> getList(Map<String, Object> whereMap, Pagination pagination) {
		return illnessDao.getList(whereMap, pagination);
	}
	
	@Override
	public Page<Illness> getPage(Map<String, Object> whereMap, Pagination pagination) {
		int count = this.getCount(whereMap);
		if(count > 0){
			List<Illness> list = this.getList(whereMap, pagination);
			return new Page<Illness>(pagination.getCurrentPage(), pagination.getPageSize(), count, list);
		}
		return new Page<Illness>(pagination.getCurrentPage(), count);
	}
}
